/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dao;

import  java.sql.*;
import javax.swing.*;

public class Connecter 
{	
        private String url = "jdbc:mysql://localhost:3306/minisig";
        private String login = "root";
        private String password = "root";
        
        private PreparedStatement ps;
        private static Connection connection = null;
        
	public java.sql.Connection getConnection() {
		return connection;
	}
	public void setConnection(java.sql.Connection connection) {
		this.connection = connection;
	}
        
        public Connecter()
	{
            
           // Connexion à la base de données
           try 
           {
               connection = DriverManager.getConnection(url,login,password);
               if(!connection.isClosed())
               {
                   System.out.println("Ouverture de la base de données!");
               }
  
           }
           catch (SQLException e) 
           {
                JOptionPane.showMessageDialog(null,"Impossible de se connecter à la base de données"); 
           }
	}

        public void closeconnection()
	{
            try 
            {
                if(!connection.isClosed())
                {
                    connection.close();
                    System.out.println("Fermeture de la base de données");
                }
            }
            catch (SQLException e)
            {
                e.printStackTrace();
	    }
	}
}
